package com.his.server.utils.dao;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.*;
import java.util.Calendar;


public class StatementAdapterImpl implements StatementAdapter.Statement {

	public StatementAdapterImpl() {
	}

	public void setInteger(PreparedStatement stmt, int idx, String dbtype,
			Integer val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 4);
		else
			stmt.setInt(idx, val.intValue());
	}

	public void setBoolean(PreparedStatement stmt, int idx, String dbtype,
			Boolean val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, -7);
		else
			stmt.setBoolean(idx, val.booleanValue());
	}

	public void setLong(PreparedStatement stmt, int idx, String dbtype, Long val)
			throws SQLException {
		if (val == null)
			stmt.setNull(idx, -5);
		else
			stmt.setLong(idx, val.longValue());
	}

	public void setShort(PreparedStatement stmt, int idx, String dbtype,
			Short val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 5);
		else
			stmt.setShort(idx, val.shortValue());
	}

	public void setFloat(PreparedStatement stmt, int idx, String dbtype,
			Float val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 6);
		else
			stmt.setFloat(idx, val.floatValue());
	}

	public void setDouble(PreparedStatement stmt, int idx, String dbtype,
			Double val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 8);
		else
			stmt.setDouble(idx, val.doubleValue());
	}

	public void setByte(PreparedStatement stmt, int idx, String dbtype, Byte val)
			throws SQLException {
		if (val == null)
			stmt.setNull(idx, -6);
		else
			stmt.setByte(idx, val.byteValue());
	}

	public void setString(PreparedStatement stmt, int idx, String dbtype,
			String val) throws SQLException {
		if (val == null || val.length() == 0)
			stmt.setNull(idx, 12);
		else
			stmt.setString(idx, val);
	}

	public Boolean getBoolean(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		boolean val = rs.getBoolean(idx);
		Boolean ret = null;
		if (!rs.wasNull())
			ret = Boolean.valueOf(val);
		return ret;
	}

	public Integer getInteger(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		int val = rs.getInt(idx);
		Integer ret = null;
		if (!rs.wasNull())
			ret = new Integer(val);
		return ret;
	}

	public Long getLong(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		long val = rs.getLong(idx);
		Long ret = null;
		if (!rs.wasNull())
			ret = new Long(val);
		return ret;
	}

	public Short getShort(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		short val = rs.getShort(idx);
		Short ret = null;
		if (!rs.wasNull())
			ret = new Short(val);
		return ret;
	}

	public Float getFloat(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		float val = rs.getFloat(idx);
		Float ret = null;
		if (!rs.wasNull())
			ret = new Float(val);
		return ret;
	}

	public Double getDouble(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		double val = rs.getDouble(idx);
		Double ret = null;
		if (!rs.wasNull())
			ret = new Double(val);
		return ret;
	}

	public Byte getByte(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		byte val = rs.getByte(idx);
		Byte ret = null;
		if (!rs.wasNull())
			ret = new Byte(val);
		return ret;
	}

	public String getString(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		String ret = rs.getString(idx);
		return ret;
	}

	public Boolean getBoolean(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		boolean val = cstmt.getBoolean(idx);
		Boolean ret = null;
		if (!cstmt.wasNull())
			ret = Boolean.valueOf(val);
		return ret;
	}

	public Integer getInteger(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		int val = cstmt.getInt(idx);
		Integer ret = null;
		if (!cstmt.wasNull())
			ret = new Integer(val);
		return ret;
	}

	public Long getLong(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		long val = cstmt.getLong(idx);
		Long ret = null;
		if (!cstmt.wasNull())
			ret = new Long(val);
		return ret;
	}

	public Short getShort(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		short val = cstmt.getShort(idx);
		Short ret = null;
		if (!cstmt.wasNull())
			ret = new Short(val);
		return ret;
	}

	public Float getFloat(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		float val = cstmt.getFloat(idx);
		Float ret = null;
		if (!cstmt.wasNull())
			ret = new Float(val);
		return ret;
	}

	public Double getDouble(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		double val = cstmt.getDouble(idx);
		Double ret = null;
		if (!cstmt.wasNull())
			ret = new Double(val);
		return ret;
	}

	public Byte getByte(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		byte val = cstmt.getByte(idx);
		Byte ret = null;
		if (!cstmt.wasNull())
			ret = new Byte(val);
		return ret;
	}

	public String getString(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		String ret = cstmt.getString(idx);
		return ret;
	}

	public void setBigDecimal(PreparedStatement stmt, int idx, String dbtype,
			BigDecimal val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 2);
		else
			stmt.setBigDecimal(idx, val);
	}

	public BigDecimal getBigDecimal(CallableStatement cstmt, int idx,
			String dbtype) throws SQLException {
		BigDecimal ret = cstmt.getBigDecimal(idx);
		return ret;
	}

	public BigDecimal getBigDecimal(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		BigDecimal ret = rs.getBigDecimal(idx);
		return ret;
	}

	public void setDate(PreparedStatement stmt, int idx, String dbtype, Date val)
			throws SQLException {
		if (val == null)
			stmt.setNull(idx, 91);
		else
			stmt.setDate(idx, val);
	}

	public void setDate(PreparedStatement stmt, int idx, String dbtype,
			Date val, Calendar cal) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 91);
		else
			stmt.setDate(idx, val, cal);
	}

	public void setTime(PreparedStatement stmt, int idx, String dbtype, Time val)
			throws SQLException {
		if (val == null)
			stmt.setNull(idx, 92);
		else
			stmt.setTime(idx, val);
	}

	public void setTime(PreparedStatement stmt, int idx, String dbtype,
			Time val, Calendar cal) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 92);
		else
			stmt.setTime(idx, val, cal);
	}

	public void setTimestamp(PreparedStatement stmt, int idx, String dbtype,
			Timestamp val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 93);
		else
			stmt.setTimestamp(idx, val);
	}

	public void setTimestamp(PreparedStatement stmt, int idx, String dbtype,
			Timestamp val, Calendar cal) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 93);
		else
			stmt.setTimestamp(idx, val, cal);
	}

	public Date getDate(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		Date ret = rs.getDate(idx);
		return ret;
	}

	public Date getDate(ResultSet rs, int idx, String dbtype, Calendar cal)
			throws SQLException {
		Date ret = rs.getDate(idx);
		return ret;
	}

	public Time getTime(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		Time ret = rs.getTime(idx);
		return ret;
	}

	public Time getTime(ResultSet rs, int idx, String dbtype, Calendar cal)
			throws SQLException {
		Time ret = rs.getTime(idx);
		return ret;
	}

	public Timestamp getTimestamp(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		Timestamp ret = rs.getTimestamp(idx);
		return ret;
	}

	public Timestamp getTimestamp(ResultSet rs, int idx, String dbtype,
			Calendar cal) throws SQLException {
		Timestamp ret = rs.getTimestamp(idx);
		return ret;
	}

	public Date getDate(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		Date ret = cstmt.getDate(idx);
		return ret;
	}

	public Date getDate(CallableStatement cstmt, int idx, String dbtype,
			Calendar cal) throws SQLException {
		Date ret = cstmt.getDate(idx);
		return ret;
	}

	public Time getTime(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		Time ret = cstmt.getTime(idx);
		return ret;
	}

	public Time getTime(CallableStatement cstmt, int idx, String dbtype,
			Calendar cal) throws SQLException {
		Time ret = cstmt.getTime(idx);
		return ret;
	}

	public Timestamp getTimestamp(CallableStatement cstmt, int idx,
			String dbtype) throws SQLException {
		Timestamp ret = cstmt.getTimestamp(idx);
		return ret;
	}

	public Timestamp getTimestamp(CallableStatement cstmt, int idx,
			String dbtype, Calendar cal) throws SQLException {
		Timestamp ret = cstmt.getTimestamp(idx);
		return ret;
	}

	public void setBlob(PreparedStatement stmt, int idx, String dbtype, Blob val)
			throws SQLException {
		if (val == null)
			stmt.setNull(idx, 2004);
		else
			stmt.setBlob(idx, val);
	}

	public void setClob(PreparedStatement stmt, int idx, String dbtype, Clob val)
			throws SQLException {
		if (val == null)
			stmt.setNull(idx, 2005);
		else
			stmt.setClob(idx, val);
	}

	public Blob getBlob(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		Blob ret = rs.getBlob(idx);
		return ret;
	}

	public Clob getClob(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		Clob ret = rs.getClob(idx);
		return ret;
	}

	public Blob getBlob(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		Blob ret = cstmt.getBlob(idx);
		return ret;
	}

	public Clob getClob(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		Clob ret = cstmt.getClob(idx);
		return ret;
	}

	public void setBytes(PreparedStatement stmt, int idx, String dbtype,
			byte val[]) throws SQLException {
		if (val == null)
			stmt.setNull(idx, -3);
		else
			stmt.setBytes(idx, val);
	}

	public void setArray(PreparedStatement stmt, int idx, String dbtype,
			Array val) throws SQLException {
		if (val == null)
			stmt.setNull(idx, 2003);
		else
			stmt.setArray(idx, val);
	}

	public byte[] getBytes(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		byte ret[] = rs.getBytes(idx);
		return ret;
	}

	public Array getArray(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		Array ret = rs.getArray(idx);
		return ret;
	}

	public byte[] getBytes(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		byte ret[] = cstmt.getBytes(idx);
		return ret;
	}

	public Array getArray(CallableStatement cstmt, int idx, String dbtype)
			throws SQLException {
		Array ret = cstmt.getArray(idx);
		return ret;
	}

	public void setBinaryStream(PreparedStatement stmt, int idx, String dbtype,
			InputStream val, int length) throws SQLException {
		if (val == null)
			stmt.setNull(idx, -4);
		else
			stmt.setBinaryStream(idx, val, length);
	}

	public void setAsciiStream(PreparedStatement stmt, int idx, String dbtype,
			InputStream val, int length) throws SQLException {
		if (val == null)
			stmt.setNull(idx, -1);
		else
			stmt.setAsciiStream(idx, val, length);
	}

	public void setCharacterStream(PreparedStatement stmt, int idx,
			String dbtype, Reader val, int length) throws SQLException {
		if (val == null)
			stmt.setNull(idx, -1);
		else
			stmt.setCharacterStream(idx, val, length);
	}

	public InputStream getBinaryStream(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		InputStream ret = rs.getBinaryStream(idx);
		return ret;
	}

	public InputStream getAsciiStream(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		InputStream ret = rs.getAsciiStream(idx);
		return ret;
	}

	public Reader getCharacterStream(ResultSet rs, int idx, String dbtype)
			throws SQLException {
		Reader ret = rs.getCharacterStream(idx);
		return ret;
	}
}
